@echo off
setlocal enabledelayedexpansion

REM 设置编译器
set COMPILER=g++

REM 设置源代码和头文件目录
set SRC_DIR=src
set INCLUDE_DIR=include

REM 设置输出文件名
set OUTPUT=program.exe

REM 设置编译选项
set CXXFLAGS=-Wall -Wextra -std=c++11 -finput-charset=UTF-8 -fexec-charset=GBK

REM 输出变量的值以进行调试
echo Compiler: %COMPILER%
echo Source directory: %SRC_DIR%
echo Include directory: %INCLUDE_DIR%
echo Output file: %OUTPUT%
echo Compiler flags: %CXXFLAGS%

REM 检查 Main.cpp 文件是否存在
if not exist "Main.cpp" (
    echo Error: Main.cpp file not found!
    pause
    exit /b
)

REM 查找所有的源文件
set SOURCES=Main.cpp
for %%f in (%SRC_DIR%\*.cpp) do (
    set SOURCES=!SOURCES! %%f
)

REM 输出找到的源文件列表
echo Source files: %SOURCES%

REM 编译命令
%COMPILER% %CXXFLAGS% -I %INCLUDE_DIR% %SOURCES% -o %OUTPUT%

REM 检查编译是否成功
if %errorlevel% neq 0 (
    echo Compilation failed!
    pause
) else (
    echo Compilation succeeded! Output file is %OUTPUT%
    pause
    REM 运行生成的可执行文件
    %OUTPUT%
)
pause
